package org.example.projecttwo.mapper.article;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.example.projecttwo.entity.article.Article;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 文章Mapper接口
 */
public interface ArticleMapper extends BaseMapper<Article> {

    /**
     * 分页条件查询文章
     */
    IPage<Article> selectByCondition(Page<Article> page,
                                     @Param("status") Integer status,
                                     @Param("partitionCode") String partitionCode,
                                     @Param("isFeatured") Integer isFeatured,
                                     @Param("keyword") String keyword,
                                     @Param("startTime") String startTime,
                                     @Param("endTime") String endTime);

    /**
     * 批量更新文章状态
     */
    void batchUpdateStatus(@Param("ids") List<Long> ids,
                           @Param("status") Integer status,
                           @Param("time") LocalDateTime time);

    /**
     * 批量下架文章
     */
    void batchUnpublish(@Param("ids") List<Long> ids,
                        @Param("status") Integer status,
                        @Param("reason") Integer offShelfReason,
                        @Param("time") LocalDateTime offShelfTime);

    /**
     * 批量删除文章
     */
    void batchDelete(@Param("ids") List<Long> ids,
                     @Param("deleted") Integer deleted,
                     @Param("reason") Integer deleteReason,
                     @Param("remark") String deleteRemark);

    /**
     * 审核文章
     */
    void auditArticle(@Param("id") Long id,
                      @Param("result") Integer auditResult,
                      @Param("reason") String rejectReason,
                      @Param("auditUser") String auditUser,
                      @Param("time") LocalDateTime auditTime);

    /**
     * 批量审核文章
     */
    void batchAudit(@Param("ids") List<Long> ids,
                    @Param("result") Integer auditResult,
                    @Param("reason") String rejectReason,
                    @Param("auditUser") String auditUser,
                    @Param("time") LocalDateTime auditTime);

    /**
     * 获取文章统计数据
     */
    Map<String, Integer> getArticleStatistics(@Param("id") Long id);

    /**
     * 增加文章浏览量
     */
    void increaseViewCount(@Param("id") Long id);

    /**
     * 提交草稿审核
     */
    void submitDraftForAudit(@Param("id") Long id,
                             @Param("coverUrl") String coverUrl,
                             @Param("strategy") Integer publishStrategy,
                             @Param("publishTime") String publishTime,
                             @Param("submitTime") LocalDateTime submitAuditTime);

    Article selectByIdWithAllFields(Long id);
    String selectMaxArticleNo();

    /**
     * 批量永久删除文章
     */
    void batchPermanentlyDelete(@Param("ids") List<Long> ids);
}